package com.syxx.oa.service.impl;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.syxx.oa.dao.ApproveDao1;
import com.syxx.oa.dao.PersonnelRequirementDao;
import com.syxx.oa.domain.ApproveInfo_1;
import com.syxx.oa.service.ApproveService1;

@Service
public class ApproveServiceImpl1 implements ApproveService1 {

	private ApproveDao1 approveDao;
	private PersonnelRequirementDao troubleTicketDao;
	
	@Autowired
	public void setApproveDao(ApproveDao1 approveDao) {
		this.approveDao = approveDao;
	}

	@Autowired
	public void setTroubleTicketDao(PersonnelRequirementDao troubleTicketDao) {
		this.troubleTicketDao = troubleTicketDao;
	}

	public void add(ApproveInfo_1 approveInfo,Boolean isagree) {
		approveInfo.setApproveTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
		if(isagree == null){
//			approveInfo.setApproveType("提交");
		}else{
			approveInfo.setApproveType(isagree ? "同意" : "驳回");
		}
		Long id = approveDao.add(approveInfo);
		//流程继续向下走
		troubleTicketDao.completeTask(approveInfo.getPerReq().get_id(), approveInfo.getApprover().getEmpId(),isagree,id);
	}

	public List<ApproveInfo_1> findHistoryByTroubleTicketId(
			Long troubleTicketId) {
		return approveDao.findHistoryByTroubleTicketId(troubleTicketId);
	}

}
